using System;
using System.Collections;
using NUnit.Framework;
using Rhino.Mocks;
using NHibernate;
using DecisionesInteligentes.iEvalua.Models;
using DecisionesInteligentes.iEvalua.Tests.Helpers;

namespace DecisionesInteligentes.iEvalua.Tests.Models
{
	[TestFixture]
	public class ApplicationTestCase : ActiveRecordMockTestCase<Application> {
		
		[Test]
		public void Load_Application_By_ID()
		{
			Application application = new Application {
				Id = 1,
				Name = "Test Application"
			};
			
			//ICriteria criteria = mocks.CreateMock<ICriteria>();
			
			using(mocks.Unordered())
			{
				Expect.Call(session.Load(typeof(Application), 1)).Return(application);
			}
			
			mocks.ReplayAll();
			
			using(new MockScope(session))
			{
				Application testApplication = Application.Find(1);
				
				Assert.AreEqual(testApplication, application);
			}
		}
		
		[Test]
		public void Load_All_Applications()
		{
			IList listDB = new ArrayList {
				new Application { Id = 1, Name = "App1" },
				new Application { Id = 2, Name = "App2" },
				new Application { Id = 1, Name = "App3" },
			};
			
			ICriteria criteria = mocks.CreateMock<ICriteria>();
			
			using(mocks.Unordered())
			{
				Expect.Call(session.CreateCriteria(typeof(Application))).Return(criteria);
				Expect.Call(criteria.List()).Return(listDB);
			}
			
			mocks.ReplayAll();
			
			using(new MockScope(session))
			{
				IList list = Application.FindAll();
			
				Assert.AreEqual(3, list.Count);
			}
		}
		
		[Test]
		public void Validate_Application()
		{
			Application newApp = new Application {
				Id = 1
			};
			
			Assert.IsFalse(newApp.IsValid());
			
			newApp.Name = "New application";
			Assert.IsTrue(newApp.IsValid());
			
			mocks = null;
		}
	}
}